package com.harry.resource.inner.entity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.harry.basis.BasePoEntity;
import static com.harry.configuration.ConstSettings.*;

import java.util.Date;
import java.util.Set;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Entity
public class InnerNotificationRecord extends BasePoEntity {

	private static final long serialVersionUID = 1L;

	@Column(length = MEDIUM_LENGTH, nullable = false, updatable = false)
	private String name;

	@Column(length = BASIC_LENGTH, nullable = false, updatable = false)
	private String type;

	@Fetch(FetchMode.JOIN)
	@ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
	@JoinColumn(nullable = false, updatable = false)
	private InnerTemplate template;

	@Fetch(FetchMode.JOIN)
	@ManyToMany(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
	@JoinTable(joinColumns = @JoinColumn, inverseJoinColumns = @JoinColumn)
	private Set<InnerUser> recipients;

	@Column(columnDefinition = TEXT_COLUMN, nullable = false)
	private String variables;

	@Column(columnDefinition = DEFAULT_FALSE, insertable = false, updatable = false)
	private Boolean pushSuccess;

	@Column(insertable = false, updatable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date pushTime;

	@Column(columnDefinition = TEXT_COLUMN, insertable = false, updatable = false)
	private String failReason;
}
